import http.server
import json
import random

prizes = ['HUAWEI Mate X3', 'HUAWEI Mate 50E', 'HUAWEI Mate 50', 'HUAWEI Mate X2 5G版', '谢谢惠顾']


class RequestHandler(http.server.BaseHTTPRequestHandler):

    def do_GET(self):
        self.send_response(200)
        self.send_header('Content-type', 'application/json')
        self.end_headers()
        prize = random.choice(prizes)
        response = {'prize': prize}
        self.wfile.write(json.dumps(response).encode())


if __name__ == '__main__':
    print('服务器已启动')
    server_address = ('0.0.0.0', 8000)
    httpd = http.server.HTTPServer(server_address, RequestHandler)
    httpd.serve_forever()